﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;

public partial class GUI_EditPersonal : System.Web.UI.Page
{
    string username;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (Session["uid"] == null)
        {
            Response.Redirect("Home.aspx");
        }
        else
        {
            username = (string)Session["uid"];
        }
            string name = txtfullname.Text.ToString();
            string email = txtEmail.Text.ToString();
            string birthday = txtBirth.Text.ToString();
            string address = txtAddress.Text.ToString();      
            bool mari = rbtnotMari.Checked = !rbtMari.Checked; ;
            string hobi = txtHobi.Text.ToString();
            string sport = txtSport.Text.ToString();
            string image = FuImage.FileName;
            string quali = txtQualifi.Text.ToString();
            string scho = txtSchool.Text.ToString();
            string colect = txtCollege.Text.ToString();
            string work = txtWork.Text.ToString();
            string ogani = txtOgani.Text.ToString();
            string des = txtDes.Text.ToString();
            HttpPostedFile files = FuImage.PostedFile;
            if (FuImage.HasFile == false && files.ContentLength > 500000)
            {
                lblStatus.Text = "Error!";
            }
            else     
            try
            {
                string path = Server.MapPath("~/images/" + FuImage.FileName);

                FuImage.SaveAs(path);

                lblStatus.Text = "OK !";

             }
                catch (Exception ex)
                {
                    lblStatus.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            SqlConnection cn = new SqlConnection();
            SqlCommand cmd = new SqlCommand();  
            try
            {
                cn = ToolsDT.getConnect();
                string sql = @"Update [User] Set U_fullname='"+name+"', U_email='" + email + "', U_DOB='" + birthday + "', U_address='" + address + "', Marital_status='" + mari+ "', U_hobbies='" + hobi + "',U_sports='" + sport + "',U_image='"+ image +"' , U_qualification='" + quali + "', U_School='" + scho + "', U_college='" + colect + "', U_work_status='" + work + "', U_organization='" + ogani + "', U_designation='" + des + "' where U_username ='" + username + "'";                                
                cmd.CommandText = sql;
                cmd.Connection = cn;
                cmd.ExecuteNonQuery();
                Response.Write(@"<script language='javascript'>alert('Update Successfull!')</script>");
            }
            catch
            {
            }
            finally
            {
                cn.Close();
                cmd.Dispose();
            }
        }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("HomeUser.aspx");
    }   
  }
       
